package com.example.arithmeticleetcode.leetcode.nov;


import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-11-24 09:14
 **/
public class Demo20 {

    public static void main(String[] args) {

    }

    public String getSmallestString(int n, int k) {
        return null;
    }

    public boolean isPossibleDivide(int[] nums, int k) {
        if (k == 1) return true;
        if (nums.length % k != 0) return false;
        Map<Integer, Integer> map = new HashMap<>();
        for (int num : nums) {
            map.put(num, map.getOrDefault(num, 0) + 1);
        }
        Arrays.sort(nums);
        for (int num : nums) {
            int count = map.get(num);
            if (count == 0) continue;
            map.put(num, --count);

            for (int i = 1; i < k; i++) {
                int count2 = map.get(++num);
                if (count2 == 0) return false;
                map.put(num, --count2);
            }
        }
        return true;
    }
}
